package view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import model.Conference;
import model.Database;
import model.Paper;
import model.User;

/**
 * This class is for the reviewer selection window.
 * 
 * @author Greg Coleman
 */

public class ReviewerSelection extends JFrame {

	private Conference my_conf;
	
	private Paper my_paper;
	
	private List users;
		
	private JList revList;
	
	public ReviewerSelection(Conference the_conf, Paper the_paper) {
		super();
		my_conf = the_conf;
		my_paper = the_paper;
		init();
		pack();
	}

	private void init() {	
		setPreferredSize(new Dimension(400,400));
		setLayout(new BorderLayout());
		
		JScrollPane scrollPane = new JScrollPane();
		add(scrollPane, BorderLayout.CENTER);
		
		revList = new JList(my_conf.getReviewers().toArray());
		
		revList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
		scrollPane.setViewportView(revList);
		
		JLabel lblRevSel = new JLabel("Reviewer Selection");
		lblRevSel.setFont(new Font("Tahoma", Font.PLAIN, 20));
		lblRevSel.setHorizontalAlignment(SwingConstants.CENTER);
		add(lblRevSel, BorderLayout.NORTH);
		
		JButton btnConfirm = new JButton("Confirm");
		btnConfirm.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				List l = revList.getSelectedValuesList();
				
				if (l.contains(my_paper.getAuthorObject())) {
					JOptionPane.showMessageDialog(null, "That person authored this paper. They cannot review it.");
				} else {
					my_paper.addReviewers(revList.getSelectedValuesList());
					dispose();
				}
			}	
		});
		add(btnConfirm, BorderLayout.SOUTH);
	}
}
